#{extends 'assistant_main.html' /}

#{set "moreStyles"}
<style type="text/css">
    .tab_div{
        height: 350px;
        overflow-y: scroll;
    }
    .normal_status{
        background-color: #2d9628;
    }

    .status_available{background-color: #2d9628;}
    .status_part_available{background-color: #946b15;}
    .status_unavailable{background-color: #f5f5ef;}
</style>
#{/set}

#{set 'moreScripts'}

<script type="text/javascript">
    $(function () {
        // Tabs
        $(function () {
            $("#district_tabs").tabs({
                ajaxOptions:{
                    error:function (xhr, status, index, anchor) {
                        $(anchor.hash).html("载入失败");
                    }
                }
            });
        });
    });


    var cityListAction = #{jsAction @Districts.cityList(':provinceId')/}
    function loadCities(provinceId,provinceName){
        $('#city_tab').load(cityListAction({'provinceId':provinceId}), function () {});
        $('#city_tab_title').html(provinceName + "-市列表");
        $('#district_tabs').tabs('select', 1);

        $('#county_tab').html("");
        $('#county_tab_title').html("区/县列表");
    }

    var countyListAction = #{jsAction @Districts.countyList(':cityId')/}
    function loadCounties(cityId, cityName) {
        $('#county_tab').load(countyListAction({'cityId':cityId}), function () {
        });
        $('#county_tab_title').html(cityName + "-区/县列表");
        $('#district_tabs').tabs('select', 2);
    }


    function forbid(level, districtId,districtName){
        jqConfirm("确定禁用\""+districtName+"\"吗？",function(){
            window.location='@{Districts.forbid()}?level='+level+'&districtId='+districtId;
        });
    }

    function resume(level, districtId,districtName){
        jqConfirm("确定恢复\""+districtName+"\"吗？",function(){
            window.location='@{Districts.resume()}?level='+level+'&districtId='+districtId;
        });
    }
</script>
#{/set}


<h1 id="title">行政区维护</h1>
<div class="light_bar">
    ${provList.size()} 省&nbsp;
</div>

<div id="district_tabs">
    <ul>
        <li><a href="#province_tab">省列表</a></li>
        <li><a id="city_tab_title" href="#city_tab">市列表</a></li>
        <li><a id="county_tab_title" href="#county_tab">区/县列表</a></li>
    </ul>
    <div id="province_tab" class="tab_div">
        <p>${provList.size()} 省&nbsp;</p>
        <table width="30%">
            <thead>
            <tr>
                <th class="main" width="20%">省份名称</th>
                *{<th class="main" width="15%">邮政编码</th>}*
                <th class="main" width="15%">编码</th>
                <th class="main" width="30%">状态</th>
                <th class="main" width="35%">操作</th>
            </tr>
            </thead>
        #{if provList.size()>0}
            #{list items:provList, as:'prov'}
                <tr class="${prov.cssByStatus()}">
                    <td>
                        <a href="#"
                           onclick="loadCities('${prov.disId}','${prov.disName}')">${prov.disName}</a>
                    </td>
                    <td>${prov.disId}</td>
                    <td>${prov.showStatus()}</td>
                    <td>
                        <a onclick="forbid(1,'${prov.disId}','${prov.disName}');" id="forbid_prov_${prov.disId}" #{if prov.status!=1 && prov.status!=3}style="display: none"#{/if} href="#" class="ui-state-default ui-corner-all opt_button">禁用</a>
                        <a onclick="resume(1,'${prov.disId}','${prov.disName}');" id="resume_prov_${prov.disId}" #{if prov.status!=2 && prov.status!=3}style="display: none"#{/if} href="#" class="ui-state-default ui-corner-all opt_button">恢复</a>
                        <a href="#" class="ui-state-default ui-corner-all opt_button">添加城市</a>
                    </td>
                </tr>
            #{/list}
        #{/if}
        </table>
    </div>

    <div id="city_tab" class="tab_div">
    </div>
    <div id="county_tab" class="tab_div">
    </div>
</div>



<div id="add_div" style="display: none;" title="新增行政区">
    <form id="add_form" action="@{Districts.create}" method="post">
        <table class="myTable">
            <tr>
                <td align="right" class="input_label"><label for="name" class="input_required">组织名：</label></td>
                <td><input id="name" name="name" type="text" maxlength="50"/></td>
            </tr>
            <tr>
                <td align="right" class="input_label"><label for="key" class="input_required">代码：</label></td>
                <td><input id="key" name="key" type="text" maxlength="50"/></td>
            </tr>
            <tr>
                <td align="right" class="input_label"><label for="remark">备注：</label></td>
                <td><input id="remark" name="remark" type="text" maxlength="20"/></td>
            </tr>
            <tr class="no_bottom">
                <td align="right" class="input_label no_bottom"><label for="remark">上级组织：</label></td>
                <td class="no_bottom">
                    <input type="hidden" id="parentId" name="parentId" type="text" maxlength="20"/>
                    <a href="#" id="dialog_link" class="ui-state-default ui-corner-all dialog_button"><span
                            class="ui-icon ui-icon-newwin"></span>选择</a>
                    <span id="parentName"></span>
                </td>
            </tr>
        </table>
    </form>
</div>


<div id="edit_div" style="display: none;" title="编辑行政区信息">
#{form @edit(), id:'edit_form',method:'POST'}
    <input type="hidden" id="edit_entity_id" name="userId" value=""/>

    <div id="edit_table_div">
    *{这里由ajax引入后台html代码}*
    </div>
#{/form}
</div>